﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

/// <summary>
/// 音效初始化组件，手动调用
/// </summary>
public class AudioInit : MonoBehaviour
{
    private static bool inited = false;
    public static string GlobalAudioObjectPrefab = "GlobalAudioObject";

    // Use this for initialization
    void Awake()
    {
        if (!inited)
        {
            inited = Init();            
        }
    }

    public static bool InitFromPrefab()
    {
        GameObject go = Resources.Load<GameObject>(GlobalAudioObjectPrefab);
        if (go != null)
        {
            var clone = Instantiate(go);
            DontDestroyOnLoad(clone);
            return true;
        }
        return false;
    }


    public static bool Init()
    {
        //Wwise 初始化
        GameObject gameObj = new GameObject("AudioManager");
        gameObj.AddComponent<AkTerminator>();
        AkInitializer initializer = gameObj.AddComponent<AkInitializer>();
        initializer.engineLogging = true;

        gameObj.AddComponent<AudioStudio.GlobalSoundObj>();

        AudioStudio.AudioManager.Instance.Init(gameObj);
        return true;
    }
}
